package com.gzt.bookcatalog.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;

public abstract class BaseService {
    public <T> Page<T> execute(JpaPageQueryCallback<T> callback, Pageable pageable) {
        // 执行具体的 JPA 分页查询
        Page<T> page = callback.query(pageable);
        // 将 Spring Data JPA 的 Page 对象转换为自定义的 AppPageInfo 对象
        return new PageImpl<>(page.getContent(), pageable, page.getTotalElements());
    }
}